﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DomainModel;
using Utils;
using WebUI.Utils;

namespace WebUI.Models
{
    public class CoEditProfileViewModel : BaseViewModel
    {
        public CoEditProfileViewModel()
            : base()
        { }

        public Login Login { get; set; }
        public Co Co { get; set; }

        public HttpPostedFileBase Avatar { get; set; }
        public string AvatarUrl { get; set; }

        public IEnumerable<SelectListItem> CoTypeList { get; set; }

        protected override void SetVars()
        {
            //get login obj
            //get co obj
            var q = SqlUtilities.QueryMultiple<Login, Co>(ConstUtils.SP_GetLoginAndCo, new { LoginID = Identity.LoginID });
            Login = ((IEnumerable<Login>)q.Dequeue()).FirstOrDefault();
            Co = ((IEnumerable<Co>)q.Dequeue()).FirstOrDefault();

            AvatarUrl = ImageUtils.GetAvatarRelativeUrl(AvatarType.CoAvatar, Identity.AccountID, AvatarSizeEnum.Avatar_80x80, Co.AvatarFileExtension);

            CoTypeList = ViewModelUtils.GetSelectListItems(GlobalUtilities.GetInstance().CoTypeList, Co.CoTypeID);
        }
    }
}